package learn2workqueues

import com.rabbitmq.client.CancelCallback
import com.rabbitmq.client.DeliverCallback
import com.rabbitmq.client.Delivery
import utils.RabbitMqUtils

/**

 @author HSH

 @create 2022-01-06 10:33
工作线程
 */
class Worker01 {
    private static final String QUEUE_NAME = "hello"

    static void main(String[] args) {
        def channel = RabbitMqUtils.getChannel()
        println "C2等待接收消息。。。。"
        channel.basicConsume(QUEUE_NAME,true,new DeliverCallback(){
            @Override
            void handle(String consumerTag, Delivery message) throws IOException {
                println "接收到的消息是${new String(message.getBody())}"
            }
        },new CancelCallback(){

            @Override
            void handle(String consumerTag) throws IOException {
                println "消息消息消费被中断"
            }
        })
    }
}
